DevForce Help Reference
StartParallel(IEnumerable<Func<INotifyCompleted>>,Action<CoroutineOperation>) Method
Example 


List of asynchronous functions
Optional completion handler
Start parallel exeuction of multiple asynchronous actions.
Syntax
'Declaration
 
Public Overloads Shared Function StartParallel( _
   ByVal asyncFns As IEnumerable(Of Func(Of INotifyCompleted)), _
   Optional ByVal completedHandler As Action(Of CoroutineOperation) _
) As CoroutineOperation
'Usage
 
Dim asyncFns As IEnumerable(Of Func(Of INotifyCompleted))
Dim completedHandler As Action(Of CoroutineOperation)
Dim value As CoroutineOperation
 
value = Coroutine.StartParallel(asyncFns, completedHandler)

Parameters

asyncFns
List of asynchronous functions
completedHandler
Optional completion handler

Return Value

A CoroutineOperation representing this operation
Remarks
Used to start parallel execution of the asynchronous actions within a list of asynchronous functions. Each asychronous action is started on its own thread. Once all actions have completed, the completion handler is called. The CoroutineOperation.Notifications can be used to check the results of each action.

This overload of the StartParallel method is useful in Visual Basic, where iterators are not supported.

Example
public void CoroutineSampleParallel() {

   // Start some parallel async operations.
   var op = Coroutine.StartParallel(SampleActions);

   // Listen for completion. 
   op.Completed += (s, e) => {
     MessageBox.Show(e.Notifications.Count.ToString() + " operations completed");
     // You can loop thru notifications for results from each operation.
   };
 }

 // A block of asynchronous actions to be performed in parallel.
 private IEnumerable<INotifyCompleted> SampleActions() {

   // Start a query for all customers in specified country.
   yield return _entityManager.Customers.Where(c => c.Country == "UK").ExecuteAsync();

   // Start another query for all employees.  This will run in parallel.
   yield return _entityManager.Employees.ExecuteAsync();
 }              
   
/***************************************************************************************/
// Sample 2 - passing arguments to an iterator    
   
 public void CoroutineSampleParallel2() {

   // Start some parallel async operations.
   var op = Coroutine.StartParallel(() => SampleActions2("UK"));

   // Listen for completion. 
   op.Completed += (s, e) => {
     MessageBox.Show(e.Notifications.Count.ToString() + " operations completed");
     // You can loop thru notifications for results from each operation.
   };
 }

 // A block of asynchronous actions to be performed in parallel.
 private IEnumerable<INotifyCompleted> SampleActions2(string country) {

   // Start a query for all customers in specified country.
   yield return _em1.Customers.Where(c => c.Country == country).ExecuteAsync();

   // Start another query for all employeesin specified country. This will run in parallel.
   yield return _em1.Employees.Where(e=> e.Country == country).ExecuteAsync();
 }
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Coroutine Class
Coroutine Members
Overload List

Send Feedback